package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getRateBean;
import com.ymatou.iapi.godmch.service.getRateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*渠道商费率查询
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getRate{
	private static getRateBean bean;
	private static getRateCall call;
	
	private final static Integer channlNoAgent=500400810;//渠道无代理
	private final static Integer channlAndAgent=500400812;//渠道有代理
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("渠道商费率查询");
	}

	@Before
	public void caseUp() {
		bean=new getRateBean();
		call=new getRateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getRate_001() {
		Logger.start(true,"正例-渠道商费率查询-有费率(白名单渠道)");
		try {
			
			bean.setMchId(channlNoAgent);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(1.6d, call.getRate(), "验证rate");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getRate_001_1() {
		Logger.start(true,"正例-渠道商费率查询-有费率,有代理(白名单渠道)");
		try {
			
			bean.setMchId(channlAndAgent);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(1.8d, call.getRate(), "验证rate");
			Logger.verifyEquals(false, call.getBuyerServiceCharge(), "验证BuyerServiceCharge");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getRate_002() {
		Logger.start(true,"正例-渠道商费率查询-无费率");
		try {
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals("{}",  call.getString("result"), "验证result为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getRate_003() {
		Logger.start(true,"正例-渠道商费率查询-有费率(白名单渠道)");
		try {
			
			bean.setMchId(channlNoAgent);
			//	商家是否可以设置会员注册条款
			Map<String,Object> map=new HashMap();
			map.put("buyerServiceCharge", true);
			GodmchManageCallService.setMchAllConfig(channlNoAgent, map);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(1.6d, call.getRate(), "验证rate");
			Logger.verifyEquals(true, call.getBuyerServiceCharge(), "验证BuyerServiceCharge");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}